/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.wapproject.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class ConfigurationUtils {
    private static Logger logger = Logger.getLogger( ConfigurationUtils.class );
    
    public static final String CONFIG_FILE				= "/wapproject.properties";
    public static final String USERNAME					= "net.wapproject.username";
    public static final String PASSWORD 				= "net.wapproject.password";
    public static final String KEY_SOURCE_FOLDER		= "net.wapproject.saveimgdownload";
    public static final String CONTEXTPATH 				= "net.wapproject.contextpath";
    public static final String FORGOTPASSWORD			= "net.wapproject.forgotpassword";
    public static final String HOMEPAGE_WP				= "net.wapproject.homepage";
    public static final String FILE_URL 				= "net.wapproject.fileurl";
    public static Properties PROPERTIES = null;

    /**
     * Get configuration of this application.
     *
     * @return properties
     */
    public static Properties getConfig() {
        String location = " - getConfig() - ";
        if ( PROPERTIES == null ) {
            logger.debug( location + " creating configuration " + CONFIG_FILE);
            InputStream is = ConfigurationUtils.class.getResourceAsStream(CONFIG_FILE);
            PROPERTIES = new Properties();
            try {
                logger.debug(location + "loading configuration");
                PROPERTIES.load(is);
                logger.debug( location + "successfully loaded configuration");
            } catch ( IOException ioe ) {
                logger.error(location + "loading configuration error " + ioe.getMessage() );
            } // end if
        } // end if

        return PROPERTIES;
    } // end of getConfig()


    /**
     * Get config property value.
     *
     * @param key   key
     * @return      value
     */
    public static String get(String key) {
        return getConfig().getProperty( key );
    }
}
